﻿using System.Collections;
using System.Collections.Generic;

using Entitas;

using UnityEngine;

namespace Internal
{
    /// <summary>
    /// 用来创建实体的系统
    /// </summary>
    public class CreatorSystem : ReactiveSystem<InputEntity>
    {
        private GameContext gameContext;


        public CreatorSystem(Contexts context) : base(context.input)
        {
            gameContext = context.game;
        }


        protected override ICollector<InputEntity> GetTrigger(IContext<InputEntity> context)
        {
            return context.CreateCollector(InputMatcher.InternalMouseEvent);
        }

        protected override void Execute(List<InputEntity> entities)
        {
            foreach (var item in entities)
            {
                var gameEntity = gameContext.CreateEntity();
                gameEntity.AddInternalSprite("模特无背景");
                Vector2 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                gameEntity.AddInternalPositon(pos);
                float dir = 0;
                gameEntity.AddInternalDirection(dir);
            }
        }

        protected override bool Filter(InputEntity entity)
        {
            return entity.hasInternalMouseEvent
                && entity.internalMouseEvent.clickEvent == MouseClickEvent.DOWN
                && entity.internalMouseEvent.mouseEvent == MouseEvent.LEFT;
        }


    }
}

